home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 April / PCWorld_1999-04_cd.bin / Software / Vyzkuste / LearnVB6 / VB Code / Class 4 / Exercise4.frm < prev    next >
Text File  |  1998-04-19  |  14KB  |  451 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmStudent 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Student Profile"
  6.    ClientHeight    =   4485
  7.    ClientLeft      =   1185
  8.    ClientTop       =   1515
  9.    ClientWidth     =   6690
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    PaletteMode     =   1  'UseZOrder
  14.    ScaleHeight     =   4485
  15.    ScaleWidth      =   6690
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.Frame Frame3 
  18.       Caption         =   "Picture"
  19.       BeginProperty Font 
  20.          Name            =   "MS Sans Serif"
  21.          Size            =   9.75
  22.          Charset         =   0
  23.          Weight          =   700
  24.          Underline       =   0   'False
  25.          Italic          =   -1  'True
  26.          Strikethrough   =   0   'False
  27.       EndProperty
  28.       Height          =   3252
  29.       Left            =   4560
  30.       TabIndex        =   20
  31.       Top             =   720
  32.       Width           =   1932
  33.       Begin VB.CommandButton cmdLoad 
  34.          Caption         =   "&Load Picture"
  35.          Height          =   492
  36.          Left            =   360
  37.          TabIndex        =   23
  38.          Top             =   2640
  39.          Width           =   1212
  40.       End
  41.       Begin VB.Image imgStudent 
  42.          BorderStyle     =   1  'Fixed Single
  43.          Height          =   2292
  44.          Left            =   120
  45.          Stretch         =   -1  'True
  46.          Top             =   240
  47.          Width           =   1692
  48.       End
  49.    End
  50.    Begin VB.CommandButton cmdExit 
  51.       Caption         =   "E&xit"
  52.       Height          =   492
  53.       Left            =   2760
  54.       TabIndex        =   19
  55.       Top             =   3720
  56.       Width           =   1092
  57.    End
  58.    Begin VB.CommandButton cmdNew 
  59.       Caption         =   "&New Profile"
  60.       Height          =   492
  61.       Left            =   2760
  62.       TabIndex        =   6
  63.       Top             =   3120
  64.       Width           =   1092
  65.    End
  66.    Begin VB.CommandButton cmdShow 
  67.       Caption         =   "&Show Profile"
  68.       Height          =   495
  69.       Left            =   2760
  70.       TabIndex        =   5
  71.       Top             =   2520
  72.       Width           =   1095
  73.    End
  74.    Begin VB.Frame Frame4 
  75.       Caption         =   "Grade Level"
  76.       BeginProperty Font 
  77.          Name            =   "MS Sans Serif"
  78.          Size            =   9.75
  79.          Charset         =   0
  80.          Weight          =   700
  81.          Underline       =   0   'False
  82.          Italic          =   -1  'True
  83.          Strikethrough   =   0   'False
  84.       EndProperty
  85.       Height          =   2532
  86.       Left            =   120
  87.       TabIndex        =   4
  88.       Top             =   1800
  89.       Width           =   1932
  90.       Begin VB.OptionButton optLevel 
  91.          Caption         =   "Grade 6"
  92.          Height          =   255
  93.          Index           =   5
  94.          Left            =   120
  95.          TabIndex        =   22
  96.          Top             =   2160
  97.          Width           =   1335
  98.       End
  99.       Begin VB.OptionButton optLevel 
  100.          Caption         =   "Grade 5"
  101.          Height          =   255
  102.          Index           =   4
  103.          Left            =   120
  104.          TabIndex        =   21
  105.          Top             =   1800
  106.          Width           =   1335
  107.       End
  108.       Begin VB.OptionButton optLevel 
  109.          Caption         =   "Grade 4"
  110.          Height          =   255
  111.          Index           =   3
  112.          Left            =   120
  113.          TabIndex        =   18
  114.          Top             =   1440
  115.          Width           =   1335
  116.       End
  117.       Begin VB.OptionButton optLevel 
  118.          Caption         =   "Grade 3"
  119.          Height          =   255
  120.          Index           =   2
  121.          Left            =   120
  122.          TabIndex        =   17
  123.          Top             =   1080
  124.          Width           =   1215
  125.       End
  126.       Begin VB.OptionButton optLevel 
  127.          Caption         =   "Grade 2"
  128.          Height          =   255
  129.          Index           =   1
  130.          Left            =   120
  131.          TabIndex        =   16
  132.          Top             =   720
  133.          Width           =   1335
  134.       End
  135.       Begin VB.OptionButton optLevel 
  136.          Caption         =   "Grade 1"
  137.          Height          =   255
  138.          Index           =   0
  139.          Left            =   120
  140.          TabIndex        =   15
  141.          Top             =   360
  142.          Value           =   -1  'True
  143.          Width           =   1215
  144.       End
  145.    End
  146.    Begin VB.Frame Frame2 
  147.       Caption         =   "Sex"
  148.       BeginProperty Font 
  149.          Name            =   "MS Sans Serif"
  150.          Size            =   9.75
  151.          Charset         =   0
  152.          Weight          =   700
  153.          Underline       =   0   'False
  154.          Italic          =   -1  'True
  155.          Strikethrough   =   0   'False
  156.       EndProperty
  157.       Height          =   1095
  158.       Left            =   120
  159.       TabIndex        =   3
  160.       Top             =   600
  161.       Width           =   2055
  162.       Begin VB.OptionButton optSex 
  163.          Caption         =   "Female"
  164.          Height          =   255
  165.          Index           =   1
  166.          Left            =   120
  167.          TabIndex        =   14
  168.          Top             =   720
  169.          Width           =   1695
  170.       End
  171.       Begin VB.OptionButton optSex 
  172.          Caption         =   "Male"
  173.          Height          =   255
  174.          Index           =   0
  175.          Left            =   120
  176.          TabIndex        =   13
  177.          Top             =   360
  178.          Value           =   -1  'True
  179.          Width           =   1695
  180.       End
  181.    End
  182.    Begin VB.Frame Frame1 
  183.       Caption         =   "Date of Birth"
  184.       BeginProperty Font 
  185.          Name            =   "MS Sans Serif"
  186.          Size            =   9.75
  187.          Charset         =   0
  188.          Weight          =   700
  189.          Underline       =   0   'False
  190.          Italic          =   -1  'True
  191.          Strikethrough   =   0   'False
  192.       EndProperty
  193.       Height          =   1815
  194.       Left            =   2400
  195.       TabIndex        =   2
  196.       Top             =   600
  197.       Width           =   1935
  198.       Begin VB.VScrollBar vsbYear 
  199.          Height          =   375
  200.          Left            =   1560
  201.          Max             =   1800
  202.          Min             =   2100
  203.          TabIndex        =   12
  204.          Top             =   1320
  205.          Value           =   1960
  206.          Width           =   255
  207.       End
  208.       Begin VB.VScrollBar vsbDay 
  209.          Height          =   375
  210.          Left            =   1560
  211.          Max             =   1
  212.          Min             =   31
  213.          TabIndex        =   11
  214.          Top             =   840
  215.          Value           =   1
  216.          Width           =   255
  217.       End
  218.       Begin VB.VScrollBar vsbMonth 
  219.          Height          =   375
  220.          Left            =   1560
  221.          Max             =   1
  222.          Min             =   12
  223.          TabIndex        =   10
  224.          Top             =   360
  225.          Value           =   1
  226.          Width           =   255
  227.       End
  228.       Begin VB.Label lblYear 
  229.          Alignment       =   2  'Center
  230.          BackColor       =   &H00FFFFFF&
  231.          BorderStyle     =   1  'Fixed Single
  232.          BeginProperty Font 
  233.             Name            =   "MS Sans Serif"
  234.             Size            =   9.75
  235.             Charset         =   0
  236.             Weight          =   400
  237.             Underline       =   0   'False
  238.             Italic          =   0   'False
  239.             Strikethrough   =   0   'False
  240.          EndProperty
  241.          Height          =   375
  242.          Left            =   120
  243.          TabIndex        =   9
  244.          Top             =   1320
  245.          Width           =   1455
  246.       End
  247.       Begin VB.Label lblDay 
  248.          Alignment       =   2  'Center
  249.          BackColor       =   &H00FFFFFF&
  250.          BorderStyle     =   1  'Fixed Single
  251.          BeginProperty Font 
  252.             Name            =   "MS Sans Serif"
  253.             Size            =   9.75
  254.             Charset         =   0
  255.             Weight          =   400
  256.             Underline       =   0   'False
  257.             Italic          =   0   'False
  258.             Strikethrough   =   0   'False
  259.          EndProperty
  260.          Height          =   375
  261.          Left            =   120
  262.          TabIndex        =   8
  263.          Top             =   840
  264.          Width           =   1455
  265.       End
  266.       Begin VB.Label lblMonth 
  267.          Alignment       =   2  'Center
  268.          BackColor       =   &H00FFFFFF&
  269.          BorderStyle     =   1  'Fixed Single
  270.          BeginProperty Font 
  271.             Name            =   "MS Sans Serif"
  272.             Size            =   9.75
  273.             Charset         =   0
  274.             Weight          =   400
  275.             Underline       =   0   'False
  276.             Italic          =   0   'False
  277.             Strikethrough   =   0   'False
  278.          EndProperty
  279.          Height          =   375
  280.          Left            =   120
  281.          TabIndex        =   7
  282.          Top             =   360
  283.          Width           =   1455
  284.       End
  285.    End
  286.    Begin VB.TextBox txtName 
  287.       BeginProperty Font 
  288.          Name            =   "MS Sans Serif"
  289.          Size            =   9.75
  290.          Charset         =   0
  291.          Weight          =   400
  292.          Underline       =   0   'False
  293.          Italic          =   0   'False
  294.          Strikethrough   =   0   'False
  295.       EndProperty
  296.       Height          =   420
  297.       Left            =   840
  298.       TabIndex        =   0
  299.       Top             =   120
  300.       Width           =   5652
  301.    End
  302.    Begin MSComDlg.CommonDialog cdlBox 
  303.       Left            =   5280
  304.       Top             =   4080
  305.       _ExtentX        =   847
  306.       _ExtentY        =   847
  307.       _Version        =   327681
  308.       DefaultExt      =   "bmp"
  309.       Filter          =   "Bitmaps (*.bmp)|*.bmp"
  310.    End
  311.    Begin VB.Label Label1 
  312.       Caption         =   "Name"
  313.       BeginProperty Font 
  314.          Name            =   "MS Sans Serif"
  315.          Size            =   9.75
  316.          Charset         =   0
  317.          Weight          =   700
  318.          Underline       =   0   'False
  319.          Italic          =   -1  'True
  320.          Strikethrough   =   0   'False
  321.       EndProperty
  322.       Height          =   255
  323.       Left            =   120
  324.       TabIndex        =   1
  325.       Top             =   240
  326.       Width           =   735
  327.    End
  328. End
  329. Attribute VB_Name = "frmStudent"
  330. Attribute VB_GlobalNameSpace = False
  331. Attribute VB_Creatable = False
  332. Attribute VB_PredeclaredId = True
  333. Attribute VB_Exposed = False
  334. Option Explicit
  335. Dim Months(12) As String
  336. Dim Days(12) As Integer
  337. Dim Grade As String
  338.  
  339. Private Sub cmdExit_Click()
  340. End
  341. End Sub
  342.  
  343. Private Sub cmdLoad_Click()
  344. cdlBox.ShowOpen
  345. imgStudent.Picture = LoadPicture(cdlBox.filename)
  346. End Sub
  347.  
  348. Private Sub cmdNew_Click()
  349. 'Blank out name and picture
  350. txtName.Text = ""
  351. imgStudent.Picture = LoadPicture("")
  352. End Sub
  353.  
  354. Private Sub cmdShow_Click()
  355. Dim Is_Leap As Integer
  356. Dim Msg As String, Age As Integer, Pronoun As String
  357. Dim M As Integer, D As Integer, Y As Integer
  358.  
  359. 'Check for leap year and if February is current month
  360. If vsbMonth.Value = 2 And vsbYear.Value Mod 4 = 0 And vsbYear.Value Mod 100 <> 0 Then
  361.   Is_Leap = 1
  362. Else
  363.   Is_Leap = 0
  364. End If
  365.  
  366. 'Check to make sure current day doesn't exceed number of days in month
  367. If vsbDay.Value > Days(vsbMonth.Value) + Is_Leap Then
  368.   MsgBox "Only" + Str(Days(vsbMonth.Value) + Is_Leap) + " days in " + Months(vsbMonth.Value), vbOKOnly + vbCritical, "Invalid Birth Date"
  369.   Exit Sub
  370. End If
  371.  
  372. 'Get current date to compute age
  373. M = Val(Format(Now, "mm"))
  374. D = Val(Format(Now, "dd"))
  375. Y = Val(Format(Now, "yyyy"))
  376. Age = Y - vsbYear
  377. If vsbMonth.Value > M Or (vsbMonth.Value = M And vsbDay > D) Then Age = Age - 1
  378.  
  379. 'Check for valid age
  380. If Age < 0 Then
  381.   MsgBox "Birth date is before current date.", vbOKOnly + vbCritical, "Invalid Birth Date"
  382.   Exit Sub
  383. End If
  384.  
  385. 'Check to make sure name entered
  386. If txtName.Text = "" Then
  387.   MsgBox "The profile requires a name.", vbOKOnly + vbCritical, "No Name Entered"
  388.   Exit Sub
  389. End If
  390.  
  391. 'Put together student profile message
  392. Msg = txtName.Text + " is a student in the " + Grade + " grade." + vbCr
  393. If optSex(0).Value = True Then Pronoun = "He " Else Pronoun = "She "
  394. Msg = Msg + Pronoun + " is" + Str(Age) + " years old." + vbCr
  395. MsgBox Msg, vbOKOnly, "Student Profile"
  396. End Sub
  397.  
  398.  
  399. Private Sub Form_Load()
  400. 'Set arrays for dates and initialize labels
  401. Months(1) = "January": Days(1) = 31
  402. Months(2) = "February": Days(2) = 28
  403. Months(3) = "March": Days(3) = 31
  404. Months(4) = "April": Days(4) = 30
  405. Months(5) = "May": Days(5) = 31
  406. Months(6) = "June": Days(6) = 30
  407. Months(7) = "July": Days(7) = 31
  408. Months(8) = "August": Days(8) = 31
  409. Months(9) = "September": Days(9) = 30
  410. Months(10) = "October": Days(10) = 31
  411. Months(11) = "November": Days(11) = 30
  412. Months(12) = "December": Days(12) = 31
  413. lblMonth.Caption = Months(vsbMonth.Value)
  414. lblDay.Caption = Str(vsbDay.Value)
  415. lblYear.Caption = Str(vsbYear.Value)
  416. Grade = "first"
  417. End Sub
  418.  
  419.  
  420. Private Sub optLevel_Click(Index As Integer)
  421. Select Case Index
  422. Case 0
  423.    Grade = "first"
  424. Case 1
  425.    Grade = "second"
  426. Case 2
  427.    Grade = "third"
  428. Case 3
  429.    Grade = "fourth"
  430. Case 4
  431.    Grade = "fifth"
  432. Case 5
  433.    Grade = "sixth"
  434. End Select
  435. End Sub
  436.  
  437. Private Sub vsbDay_Change()
  438. lblDay.Caption = Str(vsbDay.Value)
  439. End Sub
  440.  
  441. Private Sub vsbMonth_Change()
  442. lblMonth.Caption = Months(vsbMonth.Value)
  443. End Sub
  444.  
  445.  
  446. Private Sub vsbYear_Change()
  447. lblYear.Caption = Str(vsbYear.Value)
  448. End Sub
  449.  
  450.  
  451.